package edu.bit.water.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;

public class Test {
    public static void main(String[] args) {
        Connection conn = Base.getConn();
        String sql = "insert into entity_classified_standard(INDUSTRY_ID,INDUSTRY_DIRECTION,INDUSTRY_STATUS,VALUE,PRODUCT_NAME,PROCESS_ROUTE,UNIT)values (?,?,?,?,?,?,?)";
        PreparedStatement pstmt;
        long START = 0, END = 0;
        /*
        try {
            Calendar time = Calendar.getInstance();
            time.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2019-05-01"));
            START = time.getTimeInMillis();
            time.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2019-05-13"));
            END = time.getTimeInMillis();
        } catch (Exception e) {
            e.printStackTrace();
        }*/
        try {
            pstmt = (PreparedStatement) conn.prepareStatement(sql);
            for (int i = 0; i < 5; i++) {
                //pstmt.setTimestamp(1, new Timestamp(new Random().nextInt((int) (END - START + 1)) + START));
                pstmt.setInt(1, new Random().nextInt() * 100);
                pstmt.setString(2, "纺织染整产品");
                pstmt.setString(3, "现有企业");
                pstmt.setFloat(4, (int)(new Random().nextFloat() * 100));
                pstmt.setString(5, "麻纺织产品");
                pstmt.setString(6, "");
                pstmt.setString(7, "m3/t");
                pstmt.execute();
            }
            pstmt.close();
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
class Base {
    public static Connection getConn() {
        String driver = "oracle.jdbc.driver.OracleDriver";
        String url = "jdbc:oracle:thin:@10.108.18.122:1522/ORCL";
        String username = "c##szy";
        String password = "123456";
        Connection conn = null;
        try {
            Class.forName(driver);
            conn = (Connection) DriverManager.getConnection(url, username, password);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }
}